package com.service;

import com.dao.OrdinaryEmployeesDao;
import com.entity.User;

public class CalculateSalary {

	public static User calculate(User user) {
		float totalwages;
		float meritwages;
		float punishingwages;
		
		meritwages = user.getOvertimestandard() * user.getOvertime()
					+ user.getOvertimestandard() * user.getWeekovertime() * 2
					+ user.getOvertimestandard() * user.getFestovertime() * 3
					+ user.getFestivalwages() + user.getYearendwages()
					+ user.getCommission() ;
		punishingwages = user.getAbsentstandard() * user.getAbsentcount()
						+ user.getLeavestandard() * user.getLeavecount();
		totalwages = user.getBasewages() + meritwages - punishingwages;
		
		user.setTotalwages(totalwages);
		user.setMeritwages(meritwages);
		user.setPunishingwages(punishingwages);
		
		OrdinaryEmployeesDao.updateUserInfo(user.getUserid(), "totalwages", totalwages);
		OrdinaryEmployeesDao.updateUserInfo(user.getUserid(), "meritwages", meritwages);
		OrdinaryEmployeesDao.updateUserInfo(user.getUserid(), "punishingwages", punishingwages);
		return user;
	}
}
